﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using RBOSS.Business.Properties;

namespace RBOSS.Business.Smtp
{
    public class SmtpMail
    {
        public static bool SendGmail(string subject, string content, string[] recipients, string from)
        {
            bool success = recipients != null && recipients.Length > 0;

            if (success)
            {
                var gmailClient = new SmtpClient
                {
                    Host = Settings.Default.Host,
                    Port = int.Parse(Settings.Default.Port),
                    EnableSsl = true,
                    UseDefaultCredentials = false,
                   
                    Credentials = new System.Net.NetworkCredential(Settings.Default.Username, Settings.Default.Password)
                };


                using (MailMessage gMessage = new MailMessage(from, recipients[0], subject, content))
                {
                    for (int i = 1; i < recipients.Length; i++)
                        gMessage.To.Add(recipients[i]);

                    try
                    {
                        gMessage.IsBodyHtml = true;
                        gmailClient.Send(gMessage);
                        success = true;
                    }
                    catch (Exception) { success = false; }
                }
            }
            return success;
        }
    }
}
